/*
 * FDSet.h
 *
 *  Created on: Jun 27, 2016
 *      Author: Lucifer
 */

#ifndef BFX_NET_FDSET_H_
#define BFX_NET_FDSET_H_

#include "./Socket.h"

namespace BFX {

class FDSet {
public:
	FDSet(
#if PLATFORM == PLATFORM_WINDOWS
			int initialCapacity = FD_SETSIZE
#endif
	);
	~FDSet();
	operator fd_set*();
	fildes_t getMaxDescriptor() const;
	void reset();
	bool set(fildes_t fd);
	bool isSet(fildes_t fd) const;

#if PLATFORM == PLATFORM_WINDOWS
private:
	void capacity(int size);

private:
	// Windows fd_set redefines.
	typedef struct {
		u_int fd_count;
		SOCKET fd_array[1];
	} fd_set_t;
	fd_set_t* _fdSet;
	int _capacity;
#else
private:
	fd_set _fdSet;
	fildes_t _maxFd;
#endif
};

} /* namespace BFX */

#endif /* BFX_NET_FDSET_H_ */
